﻿namespace System.IO
{
    /// <summary>
    /// FileStream扩展类
    /// </summary>
    public static class FileStreamEx
    {
        /// <summary>
        /// 写数据
        /// </summary>
        /// <param name="fileStream"></param>
        /// <param name="data"></param>
        public static void Write(this FileStream fileStream, Span<byte> data)
        {
            for (int i = 0; i < data.Length; i++)
            {
                fileStream.WriteByte(data[i]);
            }
        }

        /// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="fileStream"></param>
        /// <param name="buffer"></param>
        public static void Read(this FileStream fileStream, Span<byte> buffer)
        {
            var reader = new BinaryReader(fileStream);
            reader.Read(buffer);
        }
    }
}
